package services.db;

import play.Application;
import play.GlobalSettings;
import play.libs.Akka;
import scala.concurrent.duration.Duration;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @author sergiu.marin
 * @since 02.02.2014
 */
public class Global extends GlobalSettings {

    @Override
    public void onStart(Application app) {

        Akka.system().scheduler().
                schedule(
                        Duration.create(0, TimeUnit.MILLISECONDS),
                        Duration.create(30, TimeUnit.MINUTES),
                        new Runnable() {
                            public void run() {
                                play.Logger.debug("Compare task started: " + new Date());

                                new CompareTask().executeTask();
                            }
                        },
                        Akka.system().dispatcher()
                );

        Akka.system().scheduler().
                schedule(
                        Duration.create(0, TimeUnit.MILLISECONDS),
                        Duration.create(45, TimeUnit.MINUTES),
                        new Runnable() {
                            public void run() {
                                play.Logger.debug("Transfer Data task started: " + new Date());

                                new TransferDataTask().executeTask();
                            }
                        },
                        Akka.system().dispatcher()
                );
    }
}
